﻿/* Author: Achim Schnell */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AppFx.Tokenization
{    
    /// <summary>
    /// Verifiers whitespaces for a token.
    /// </summary>
    public class WhitespaceVerifier : Verifier
    {
        #region Fields

        private char ws = ' ';

        #endregion

        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="WhitespaceVerifier"/> class.
        /// </summary>
        /// <param name="tokenizer">The parent tokenizer.</param>
        public WhitespaceVerifier(ITokenizer tokenizer) : base(tokenizer) { }

        #endregion

        #region Verifier

        /// <summary>
        /// Detects if the given char matches the token's pattern.
        /// </summary>
        /// <param name="c">Char to verify for tokenization.</param>
        /// <returns>
        /// A bool indicating if the given char matches the token's pattern.
        /// </returns>
        public override bool Verify(char c)
        {
            if (ws.Equals(c))
                return true;
            else
                return false;
        }

        /// <summary>
        /// Creates the token based on the current input-pattern.
        /// </summary>
        /// <returns>
        /// An IToken containing the current input-pattern.
        /// </returns>
        protected override IToken CreateToken()
        {
            return new Token(Buffer, eTokenType.Whitespace);
        }

        #endregion
    }
}
